#!/system/bin/sh

function run_frida()
{
	lines=`ps | grep -w frida64`
	if [ -n "$lines" ]
		then
		echo $lines
		line=`echo ${lines#* }`
		line=`echo ${line%% *}`
		su -c "kill -9 $line"
	fi;
	su -c "chmod 777 /data/local/tmp/frida64"
	su -c "./data/local/tmp/frida64"
}

function run_ida()
{
	if [ $1 == "" ]
		then
		lines=`ps | grep -w ida732`
		if [ -n "$lines" ]
			then
			echo $lines
			line=`echo ${lines#* }`
			line=`echo ${line%% *}`
			su -c "kill -9 $line"
		fi;

		su -c "chmod 777  /data/local/tmp/ida732" 	
		su -c "/data/local/tmp/ida732" 
	elif 
		then
		

		lines=`ps | grep -w $1`
			echo $lines
		
		if [ -n "$lines" ]
			then
			echo $lines
			line=`echo ${lines#* }`
			line=`echo ${line%% *}`
			su -c "kill -9 $line"
		fi;

		su -c "chmod 777  /data/local/tmp/"$1
		su -c "/data/local/tmp/"$1

	fi;
}

function open_mprop()
{
	echo $1
	su -c "/data/local/tmp/mprop ro.debuggable 1" 
}

cmd1='ida'
cmd2='frida'
cmd3='mprop'

echo "command is :" $1  "param:" $2

if [ "$1" = "$cmd1" ]
then
	run_ida $2
elif [ "$1" = "$cmd2" ]
then
	run_frida
elif [ "$1" = "$cmd3" ]
then
	open_mprop $2
fi;
